import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.AbstractButton;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.Timer;

import java.awt.EventQueue;
import java.awt.Font;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Stack;

import javax.swing.SwingConstants;

public class NMMWindow extends JFrame implements MouseListener, MouseMotionListener, ActionListener  {

	//Testing the svn
	
	private JFrame frame;
	private JPanel panel_1;
	private boolean drag = false;
	JLabel piece[] = new JLabel[24];
	JLabel red[] = new JLabel[9];
	JLabel blue[] = new JLabel[9];
	private int count = 0;
	JTextArea moves = new JTextArea("00");
	JLabel label3 = new JLabel("Moves");
	int board[][] = new int[7][7];
	int isblue = 1; // blue is first
	int ci = 1;
	// current position
	int Ex = 0;
	int Ey = 0;
	int ri = -1;
	int bi = -1;
	int totalSum;
	int a, b;
	boolean isMill = false;
	boolean blueTurn = false;
	boolean placingPiece = false;
	boolean movingPiece = false;
	JLabel movingLabel = new JLabel();
	JLabel newMovingLabel = new JLabel();
	boolean freeMoving = false;
	boolean bmills[] = new boolean[16];
	boolean rmills[] = new boolean[16];
	int toRemove = 0;
	int redCount = 9;
	int blueCount = 9;
	LeaderBoard leaderBoard;
	boolean flying = false;
	
	boolean humanTurn = true;
	
	int redFlying = 0;
	int blueFlying = 0;

	private Player player1;
	private Player player2;
	private Computer comp1;
	private Computer comp2;

	final ImageIcon redcircle = new ImageIcon("redcircle.png");
	final ImageIcon bluecircle = new ImageIcon("bluecircle.png");
	
	public Pieces boardPieces[] = new Pieces[24];
	Stack<JLabel[]> boardHistory = new Stack();
	
	public Timer clock;
	public int secs = 0;
	public int mins = 0;
	public JLabel display;
	private DecimalFormat dFormat = new DecimalFormat("00");
	int playerNum = 0;

  	  
  	  
  	  JLabel text = new JLabel("Blue First");

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {	
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					NMMWindow window = new NMMWindow();
					window.frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the application.
	 */
	public NMMWindow() {
		playerNumSelect();
		initialize();
	}
	
	public void playerNumSelect(){
		String[] choices = { "1-Player", "2-Player", "CompVsComp"};
	    String input = (String) JOptionPane.showInputDialog(null, "Choose the number of players",
	        "Choose Game Player", JOptionPane.QUESTION_MESSAGE, null, // Use 
	                                                                        // default
	                                                                        // icon
	        choices, // Array of choices
	        choices[0]); // Initial choice
	    if(input.equals("1-Player")){
	    	playerNum = 1;
	    	getNames(1);
	    }
	    if(input.equals("2-Player")){
	    	playerNum = 2;
	    	getNames(2);
	    }
	    
	    if(input.equals("CompVsComp")){
	    	playerNum = 0;
	    	getNames(0);
	    }

	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 703, 600);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		JPanel panel = new JPanel();
		frame.getContentPane().add(panel, BorderLayout.NORTH);
		frame.setTitle("NineMensMorris"); //setTitle
		
		JButton btnNewGame = new JButton("New Game");
		btnNewGame.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//System.out.println("New Game was clicked.");
				if(JOptionPane.showConfirmDialog(null,"Do you want to start a new game","New", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){
					//System.out.println("New Game was clicked.");
					frame.dispose();
					NMMWindow window = new NMMWindow();
					window.frame.setVisible(true);
					count=0;//
					moves.setText("00");//
				}
			}
				
		});
		panel.add(btnNewGame);
		
		JButton btnRules = new JButton("Rules");
		
		btnRules.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				Rules rule = new Rules();	
				
			}
		});
		panel.add(btnRules);
		
		JButton btnLeaderBoard = new JButton("Leader Board");
		leaderBoard = new LeaderBoard();
		btnLeaderBoard.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseClicked(MouseEvent e) {
				leaderBoard.setVisible(true);
			}
		});
		panel.add(btnLeaderBoard);
		
		JButton btnQuit = new JButton("Quit");
		btnQuit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				if(JOptionPane.showConfirmDialog(null,"Are you sure that you want to quit the game","Quit", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION){	
				     System.exit(0);
				}
			}
		});
		panel.add(btnQuit);
		
		panel_1 = new JPanel();
		frame.getContentPane().add(panel_1, BorderLayout.CENTER);
		panel_1.setLayout(null);
		
		JPanel panel2 = new JPanel();//
		frame.getContentPane().add(panel2, BorderLayout.SOUTH);//
		 
		moves.setFont(new Font("h",20,20));//
		
		JButton btnUndo = new JButton("Undo");
		btnUndo.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				popCurrentSet();
			}
		}); 
		
		panel2.add(btnUndo);
		panel2.add(label3);//
		panel2.add(moves);//
		
		display = new JLabel();
		panel2.add(display);
		
		clock = new Timer(1000, this);
		clock.start();
		
		text.setBounds(0,215,40,20);
		
		addPieces();
		
		red[0] = new JLabel(redcircle);
		red[0].setBounds(21, 22, 30, 30);
		panel_1.add(red[0]);
		
		red[1] = new JLabel(redcircle);
		red[1].setBounds(21, 60, 30, 30);
		panel_1.add(red[1]);
		
		red[2] = new JLabel(redcircle);
		red[2].setBounds(21, 98, 30, 30);
		panel_1.add(red[2]);
		
		red[3] = new JLabel(redcircle);
		red[3].setBounds(21, 136, 30, 30);
		panel_1.add(red[3]);
		
		red[4] = new JLabel(redcircle);
		red[4].setBounds(21, 174, 30, 30);
		panel_1.add(red[4]);
		
		red[5] = new JLabel(redcircle);
		red[5].setBounds(21, 212, 30, 30);
		panel_1.add(red[5]);
		
		red[6] = new JLabel(redcircle);
		red[6].setBounds(21, 250, 30, 30);
		panel_1.add(red[6]);
		
		red[7] = new JLabel(redcircle);
		red[7].setBounds(21, 288, 30, 30);
		panel_1.add(red[7]);
		
		red[8] = new JLabel(redcircle);
		red[8].setBounds(21, 326, 30, 30);
		panel_1.add(red[8]);
		
		blue[0] = new JLabel(bluecircle);
		blue[0].setBounds(636, 22, 30, 30);
		panel_1.add(blue[0]);
		
		blue[1] = new JLabel(bluecircle);
		blue[1].setBounds(636, 60, 30, 30);
		panel_1.add(blue[1]);
		
		blue[2] = new JLabel(bluecircle);
		blue[2].setBounds(636, 98, 30, 30);
		panel_1.add(blue[2]);
		
		blue[3] = new JLabel(bluecircle);
		blue[3].setBounds(636, 136, 30, 30);
		panel_1.add(blue[3]);
		
		blue[4] = new JLabel(bluecircle);
		blue[4].setBounds(636, 174, 30, 30);
		panel_1.add(blue[4]);
		
		blue[5] = new JLabel(bluecircle);
		blue[5].setBounds(636, 212, 30, 30);
		panel_1.add(blue[5]);
		
		blue[6] = new JLabel(bluecircle);
		blue[6].setBounds(636, 250, 30, 30);
		panel_1.add(blue[6]);
		
		blue[7] = new JLabel(bluecircle);
		blue[7].setBounds(636, 288, 30, 30);
		panel_1.add(blue[7]);
		
		blue[8] = new JLabel(bluecircle);
		blue[8].setBounds(636, 326, 30, 30);
		panel_1.add(blue[8]);
		
		
		
		ImageIcon boardImage=new ImageIcon("board.gif");
		
		JLabel boardholder = new JLabel(boardImage);
		boardholder.setBounds(126, 11, 435, 435);
		panel_1.add(boardholder);
		
		if(playerNum == 1){
		JLabel name1 = new JLabel(player1.getName(), JLabel.CENTER);
		name1.setBounds(25, 400, 70, 14);
		panel_1.add(name1);
		
		JLabel name2 = new JLabel(comp1.getName(), JLabel.CENTER);
		name2.setBounds(606, 400, 70, 14);
		panel_1.add(name2);
		}
		
		if(playerNum == 2){
		JLabel name1 = new JLabel(player1.getName(), JLabel.CENTER);
		name1.setBounds(25, 400, 70, 14);
		panel_1.add(name1);
		
		JLabel name2 = new JLabel(player2.getName(), JLabel.CENTER);
		name2.setBounds(606, 400, 70, 14);
		panel_1.add(name2);
		}
		
		for(int i = 0; i<9; i++){
			   red[i].addMouseMotionListener(this); 
			   red[i].addMouseListener(this);
			   blue[i].addMouseMotionListener(this); 
			   blue[i].addMouseListener(this);
		}
		
		for(int i=0; i<16; i++){
			bmills[i]=false;
			rmills[i]=false;
		}
	
	}//end of initialize()
	
	public void actionPerformed(ActionEvent e)  {     
		if (e.getSource() == clock){      
			secs++;    
			}     
		if (secs == 60){     
			mins++;      
			secs = 0;    
			}     
   
		display.setText(dFormat.format(mins) + ":" + dFormat.format(secs));

		}

	/**
	 * Just a method that adds all of the empty pieces nodes to the board. 
	 * aslo adds their action listeners 
	 */
	public void addPieces(){
		piece[0] = new JLabel();
		piece[0].setBounds(126, 11, 30, 30);
		//boardPieces[0].setLabel(piece[0]);
		panel_1.add(piece[0]);
		
		piece[1] = new JLabel();
		piece[1].setBounds(327, 11, 30, 30);
		//boardPieces[1].setLabel(piece[1]);
		panel_1.add(piece[1]);
		
		piece[2] = new JLabel();
		piece[2].setBounds(531, 11, 30, 30);
		//boardPieces[2].setLabel(piece[2]);
		panel_1.add(piece[2]);
		
		piece[3] = new JLabel();
		piece[3].setBounds(202,87, 30, 30);
		panel_1.add(piece[3]);
		
		piece[4] = new JLabel();
		piece[4].setBounds(329, 87, 30, 30);
		panel_1.add(piece[4]);
		
		piece[5] = new JLabel();
		piece[5].setBounds(455, 87, 30, 30);
		panel_1.add(piece[5]);
			
		piece[6] = new JLabel();
		piece[6].setBounds(281, 169, 30, 30);
		panel_1.add(piece[6]);
		
		piece[7] = new JLabel();
		piece[7].setBounds(330, 169, 30, 30);
		panel_1.add(piece[7]);
		
		piece[8] = new JLabel();
		piece[8].setBounds(376, 169, 30, 30);
		panel_1.add(piece[8]);
		
		
		piece[9] = new JLabel();
		piece[9].setBounds(126, 215, 30, 30);
		panel_1.add(piece[9]);
		
		piece[10] = new JLabel();
		piece[10].setBounds(202, 215, 30, 30);
		panel_1.add(piece[10]);
		
		piece[11] = new JLabel();
		piece[11].setBounds(281, 215, 30, 30);
		panel_1.add(piece[11]);
	
		piece[12] = new JLabel();
		piece[12].setBounds(376, 215, 30, 30);
		panel_1.add(piece[12]);
		
		piece[13] = new JLabel();
		piece[13].setBounds(455, 215, 30, 30);
		panel_1.add(piece[13]);
		
		piece[14] = new JLabel();
		piece[14].setBounds(531, 215, 30, 30);
		panel_1.add(piece[14]);
		
		piece[15] = new JLabel();
		piece[15].setBounds(281, 261, 30, 30);
		panel_1.add(piece[15]);		
		
		piece[16] = new JLabel();
		piece[16].setBounds(330, 261, 30, 30);
		panel_1.add(piece[16]);
		
		piece[17] = new JLabel();
		piece[17].setBounds(376, 261, 30, 30);
		panel_1.add(piece[17]);		
		
		piece[18] = new JLabel();
		piece[18].setBounds(202, 340, 30, 30);
		panel_1.add(piece[18]);
		
		piece[19] = new JLabel();
		piece[19].setBounds(329, 340, 30, 30);
		panel_1.add(piece[19]);
		
		piece[20] = new JLabel();
		piece[20].setBounds(455, 340, 30, 30);
		panel_1.add(piece[20]);
		
		piece[21] = new JLabel();
		piece[21].setBounds(126, 416, 30, 30);
		panel_1.add(piece[21]);
		
		piece[22] = new JLabel();
		piece[22].setBounds(329, 416, 30, 30);
		panel_1.add(piece[22]);
		
		piece[23] = new JLabel();
		piece[23].setBounds(531, 416, 30, 30);
		panel_1.add(piece[23]);
		
		for(int i = 0; i<piece.length; i++){
			piece[i].addMouseListener(this);
			piece[i].setIcon(null);
			piece[i].setVisible(true);
			Pieces myPiece = new Pieces(true,piece[i], false);
	        this.enterPiece(myPiece, i);
		}
			
		
	}
	
	public void enterPiece(Pieces myPiece, int place){
		
		boardPieces[place] = myPiece;
		
		return;
	}
	
	
	/**
	 * method to get names
	 */
	public void getNames(int choice){
		
		String player1Name = null, player2Name = null;
		
		if(choice == 1){
		player1Name=JOptionPane.showInputDialog(null,"Player 1, Enter Name: ?"); 
		player1 = new Player(player1Name); 
		comp1 = new Computer("Computer");
		}
		
		if(choice == 2){
		player1Name=JOptionPane.showInputDialog(null,"Player 1, Enter Name: ?"); 
		player1 = new Player(player1Name);
		player2Name=JOptionPane.showInputDialog(null,"Player 2, Enter Name: ?"); 
		player2 = new Player(player2Name);
		}
		
		if(choice == 0){
			player1 = new Computer("Computer 1");
			player2 = new Computer("Computer 2");
		}
		
	}//end of get name
	
	
	@Override
	public void mouseDragged(MouseEvent e) {
		// TODO Auto-generated method stub
	    if (drag == true)  
	    { 
	        JComponent jc = (JComponent)e.getSource(); 
	        jc.setLocation(jc.getX()+e.getX(), jc.getY()+e.getY()); 
	    } 

	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub
		 JComponent jc = (JComponent)e.getSource();
		    JLabel j1 = (JLabel) jc;
		    
//		    if(toRemove == 1){
//		    	if(j1.getIcon()==(redcircle)){
//		    		
//		    		j1.setIcon(null);
//		    		checkForNoMills();
//		    		redCount--;
//		    	}
//		    	toRemove = 0;
//	    		checkWin();
//	    		checkFlying();
//		    }
		    deadlocked();
		    checkForNoMills();
		    setAbleToRemove();
		    
		    while(toRemove == 1){
		    	if(j1.getIcon()==redcircle){
		    		for(int i=0; i<23; i++){
		    			if(j1==boardPieces[i].getLabel()){
		    				boolean allMills = allInMills(false);
		    				if(!allMills && !(boardPieces[i].getRemovable())){
		    					JOptionPane.showMessageDialog(this, "That piece is in a mill");
		    					return;
		    				}
		    			}
		    				if(jc.getX() == 21) { 
		    					JOptionPane.showMessageDialog(this, "Can't remove a pice that isn't on the board");
		    					return;
		    				} 
		    		}
			    		j1.setIcon(null);
			    		checkForNoMills();
			    		redCount--;
				    	toRemove = 0;
				    	deadlocked();
			    		checkWin();
			    		checkFlying();
			    		return;
		    		
		    	}
		    }
		    
		    while(toRemove == -1){
		    	if(j1.getIcon()==bluecircle){
		    		for(int i=0; i<23; i++){
		    			if(j1==boardPieces[i].getLabel()){
		    				boolean allMills = allInMills(true);
		    				if(!allMills && !(boardPieces[i].getRemovable())){
		    					JOptionPane.showMessageDialog(this, "That piece is in a mill");
		    					return;
		    				}
		    			}
		    				if(jc.getX() == 636) { 
		    					JOptionPane.showMessageDialog(this, "Can't remove a pice that isn't on the board");
		    					return;
		    				} 
		    		}
			    		j1.setIcon(null);
			    		checkForNoMills();
			    		blueCount--;
				    	toRemove = 0;
				    	deadlocked();
			    		checkWin();
			    		checkFlying();

			        		if(playerNum==1 && blueTurn && !humanTurn && toRemove == 0 && count<18){
				    			int temp = comp1.placePiece(this);
				    			piece[temp].setIcon(bluecircle);
				    			boardPieces[temp].getLabel().setIcon(bluecircle);
				    			blueTurn = !blueTurn;
				    			updateCounter();
				    			mill();	
				    		}
			    		
			    		if(playerNum==1 && blueTurn && !humanTurn && toRemove == 0 && count>=18){
			    			int temp = comp1.movePiece(this);
			    			piece[temp].setIcon(bluecircle);
			    			boardPieces[temp].getLabel().setIcon(bluecircle);
			    			blueTurn = !blueTurn;
			    			updateCounter();
			    			mill();	
			    			if(playerNum==1 && toRemove==1){
			    				comp1.removePiece(this);
			    				toRemove=0;
			    			}
			    		}
			    		return;
		    		
		    	}
		    	
		    	
		    }
		    
		    for(int i=0; i<23; i++){
		    	if(j1==boardPieces[i].getLabel()){
    				if((boardPieces[i].getDeadlocked())){
    					JOptionPane.showMessageDialog(this, "That piece is deadlocked and can't move");
    					deadlocked();
    					checkWin();
    					//return;
    				}
    			}
		    }
		    
		    if(!placingPiece){   	
		    	//System.out.println("Moving piece is false");
		    	
		    	if(blueTurn){
		    		if(jc instanceof JLabel){
					
		    			//System.out.println("its a ja label with x coord at " + jc.getX());
		    		if(freeMoving||(count<18 && (jc.getX()) ==636)){
		    			if(j1.getIcon()==(bluecircle)){
		    				placingPiece = true;
							newMovingLabel = j1;
							movingLabel.setIcon(j1.getIcon());
						
		    				//System.out.println("The image is blue circle");
						
		    				j1.setIcon(null);
		    			}//end of jc instance if
		    		}
		    		}//end of blue turn if
					
				} else if(!blueTurn){
					if(jc instanceof JLabel){
						if(freeMoving || (count<18 && (jc.getX()) ==21)){
						if(j1.getIcon()==(redcircle)){
							placingPiece = true;
							newMovingLabel = j1;
							movingLabel.setIcon(j1.getIcon());
							//j1.removeMouseListener(null);
				            //j1.setLocation(0, 0);
		    				j1.setIcon(null);
						}
						}
					}
					
				}//end of red turn if

			    }
		    else if(placingPiece) {
		    	if(jc instanceof JLabel){
		    		
		    		if(((flying&&redFlying <2 && !blueTurn)||(flying&&blueFlying <2 && blueTurn)) || (checkPlacement((JLabel) jc) && checkMove((JLabel)jc, newMovingLabel))){
		    		((JLabel) jc).setIcon(movingLabel.getIcon());
		    			jc.setVisible(true);
		    	
		    			movingLabel.setIcon(null);
		    			humanTurn = false;
		    			blueTurn = !blueTurn;	
		    			placingPiece = !placingPiece;
		    			updateCounter();
		    			deadlocked();
		    			    			    			
		    			checkForNoMills();
		    			mill();
		    			if(playerNum==1 && toRemove==1){
		    				comp1.removePiece(this);
		    				toRemove=0;
		    			}
		    			if(((JLabel) jc).getIcon()==redcircle&&flying){
		    				redFlying++;
		    			}
		    			if(((JLabel) jc).getIcon()==bluecircle&&flying){
		    				blueFlying++;
		    			}
		    			    			
		    		}
		    		
		    		if(playerNum==1 && blueTurn && !humanTurn && toRemove == 0 && count <18){
		    			int temp = comp1.placePiece(this);
		    			piece[temp].setIcon(bluecircle);
		    			boardPieces[temp].getLabel().setIcon(bluecircle);
		    			blueTurn = !blueTurn;
		    			updateCounter();
		    			mill();
		    			if(playerNum==1 && toRemove==1){
		    				comp1.removePiece(this);
		    				toRemove=0;
		    			}
		    			deadlocked();
		    		}
		    		if(playerNum==1 && blueTurn && !humanTurn && toRemove == 0 && count >=18){
		    			int temp = comp1.movePiece(this);
		    			piece[temp].setIcon(bluecircle);
		    			boardPieces[temp].getLabel().setIcon(bluecircle);
		    			blueTurn = !blueTurn;
		    			updateCounter();
		    			mill();	
		    			if(playerNum==1 && toRemove==1){
		    				comp1.removePiece(this);
		    				toRemove=0;
		    			}
		    		}
		    		
		    		flying = false;
		    		return;
		    		
				}//inf of instace of 
		       
		    }//end of not moving piece 
		    

		    
		    pushCurrentSet(piece);
		    deadlocked();
		    checkWin();
		    
		
	}
	
	public boolean allInMills(boolean bluePiece){
	
		boolean allMills = false;
		
		if(bluePiece){
			for(int i=0; i<23; i++){
				if(!boardPieces[i].getRemovable() && boardPieces[i].getLabel().getIcon()==bluecircle && allMills){
					allMills = true;
				} else {
					allMills = false;
				}
			}
		} else{
			for(int i=0; i<23; i++){
				if(!boardPieces[i].getRemovable() && boardPieces[i].getLabel().getIcon()==redcircle && allMills){
					allMills = true;
				} else {
					allMills = false;
				}
			}
		}
		
		return allMills;
	}
	
	public void pushCurrentSet(JLabel currentPiece[]){
		JLabel newPiece[] = new JLabel[24];
		for(int i=0; i<23; i++){
			newPiece[i]=currentPiece[i];
		}
		boardHistory.push(newPiece);
		
	}
	
	public void popCurrentSet(){
		JLabel poppedPieces[] = (JLabel[])boardHistory.pop();
		for(int i=0; i<23; i++){
			piece[i]=poppedPieces[i];
		}
	}
	
	public void updateCounter(){
		String s1;
		count++;
		if(count == 18){
			freeMoving = true;
		}
		if (count<=9){
   	    	s1="0"+Integer.toString(count);
   	    }
   	    else{
   	    	s1 = Integer.toString(count);
   	    }
            moves.setText(s1);
	}
	
	public void checkFlying(){
		if(redCount==3 &&redFlying<1){
			redFlying++;
			flying = true;
			JOptionPane.showMessageDialog(this, "Red move 1 piece to anywhere on the board");
		}
		if(blueCount==3 && blueFlying<1){
			blueFlying++;
			flying = true;
			JOptionPane.showMessageDialog(this, "Blue move 1 piece to anywhere on the board");
		}
		
	}
	
	public void checkWin(){
		if(redCount<=2){
			JOptionPane.showMessageDialog(this, "Blue Wins!");
			leaderBoard.updateLeaderBoard(player2.getName(), count);
			
			LeaderBoard l2 = new LeaderBoard();
			l2.setVisible(true);
			
			//leaderBoard.setVisible(true);
		}
		
		if(blueCount<=2){
			JOptionPane.showMessageDialog(this, "Red Wins!");
			leaderBoard.updateLeaderBoard(player1.getName(), count);
			//leaderBoard.setVisible(true);
			LeaderBoard l2 = new LeaderBoard();
			l2.setVisible(true);
			//
		}
		int numberOfDeadlocked = 0;
		for(int i=0; i<23; i++){
			if((boardPieces[i].getLabel().getIcon()==bluecircle) &&boardPieces[i].getDeadlocked()){
				numberOfDeadlocked++;
				//System.out.println(i +" is deadlocked: Blue");
			}
		}
		//System.out.println("Number of blue deadlocked: " + numberOfDeadlocked);
		//System.out.println("BlueCount: " + blueCount);
		if(numberOfDeadlocked>=blueCount){
			JOptionPane.showMessageDialog(this, "Red Wins!");
		}
		
		numberOfDeadlocked = 0;
		for(int i=0; i<23; i++){
			if((boardPieces[i].getLabel().getIcon()==redcircle) &&boardPieces[i].getDeadlocked()){
				numberOfDeadlocked++;
				//System.out.println(i +" is deadlocked: Red");
			}
		}
		//System.out.println("Number of red deadlocked: " + numberOfDeadlocked);
		//System.out.println("RedCount: " + redCount);
		if(numberOfDeadlocked>=redCount){
			JOptionPane.showMessageDialog(this, "Blue Wins!");
		}
		
	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void mousePressed(MouseEvent e) {
		// TODO Auto-generated method stub
	}
	
	
	@Override
	public void mouseReleased(MouseEvent e){
			
		
	}
	
	public boolean checkPlacement(JLabel spot){
		
		boolean legalMove = true;
		
		for(int i=0; i<9; i++){
			if((red[i].getLocation().equals( spot.getLocation())) || (blue[i].getLocation().equals(spot.getLocation()))){
			//System.out.println("Invalid Move");
			legalMove = false;
			JOptionPane.showMessageDialog(this, "This place has a piece, please pick a new spot.");
			break;
			}
		}
			
			for(int j=0; j<24; j++){
				if((piece[j].getLocation().equals( spot.getLocation())) && (piece[j].getIcon()==bluecircle || piece[j].getIcon()==redcircle)){
				//System.out.println("Invalid Move");
				legalMove = false;
				JOptionPane.showMessageDialog(this, "This place has a piece, please pick a new spot.");
				break;
				}
		}
		
		
		
			return legalMove;
	}
		
	
	
	public void mill (){
		if((piece[0].getIcon()==bluecircle)&&(piece[1].getIcon()==bluecircle)&&(piece[2].getIcon()==bluecircle)&&!bmills[0]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[0]=true;
			toRemove=1;
			boardPieces[0].setRemovable(false); boardPieces[1].setRemovable(false); boardPieces[2].setRemovable(false);
		}
		
		if((piece[3].getIcon()==bluecircle)&&(piece[4].getIcon()==bluecircle)&&(piece[5].getIcon()==bluecircle)&&!bmills[1]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[1]=true;
			toRemove=1;
			boardPieces[3].setRemovable(false); boardPieces[4].setRemovable(false); boardPieces[5].setRemovable(false);
		}
		
		if((piece[6].getIcon()==bluecircle)&&(piece[7].getIcon()==bluecircle)&&(piece[8].getIcon()==bluecircle)&&!bmills[2]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[2]=true;
			toRemove=1;
			boardPieces[6].setRemovable(false); boardPieces[7].setRemovable(false); boardPieces[8].setRemovable(false);
		} 
		
		if((piece[9].getIcon()==bluecircle)&&(piece[10].getIcon()==bluecircle)&&(piece[11].getIcon()==bluecircle)&&!bmills[3]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[3]=true;
			toRemove=1;
			boardPieces[9].setRemovable(false); boardPieces[10].setRemovable(false); boardPieces[11].setRemovable(false);
		} 
		
		if((piece[12].getIcon()==bluecircle)&&(piece[13].getIcon()==bluecircle)&&(piece[14].getIcon()==bluecircle)&&!bmills[4]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[4]=true;
			toRemove=1;
			boardPieces[12].setRemovable(false); boardPieces[13].setRemovable(false); boardPieces[14].setRemovable(false);
		} 
		
		if((piece[15].getIcon()==bluecircle)&&(piece[16].getIcon()==bluecircle)&&(piece[17].getIcon()==bluecircle)&&!bmills[5]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[5]=true;
			toRemove=1;
			boardPieces[15].setRemovable(false); boardPieces[16].setRemovable(false); boardPieces[17].setRemovable(false);
		} 
		
		if((piece[18].getIcon()==bluecircle)&&(piece[19].getIcon()==bluecircle)&&(piece[20].getIcon()==bluecircle)&&!bmills[6]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[6]=true;
			toRemove=1;
			boardPieces[18].setRemovable(false); boardPieces[19].setRemovable(false); boardPieces[20].setRemovable(false);
		} 
		
		if((piece[21].getIcon()==bluecircle)&&(piece[22].getIcon()==bluecircle)&&(piece[23].getIcon()==bluecircle)&&!bmills[7]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[7]=true;
			toRemove=1;
			boardPieces[21].setRemovable(false); boardPieces[22].setRemovable(false); boardPieces[23].setRemovable(false);
		} 
		
		if((piece[0].getIcon()==bluecircle)&&(piece[9].getIcon()==bluecircle)&&(piece[21].getIcon()==bluecircle)&&!bmills[8]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[8]=true;
			toRemove=1;
			boardPieces[0].setRemovable(false); boardPieces[9].setRemovable(false); boardPieces[21].setRemovable(false);
		}
		
		if((piece[3].getIcon()==bluecircle)&&(piece[10].getIcon()==bluecircle)&&(piece[18].getIcon()==bluecircle)&&!bmills[9]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[9]=true;
			toRemove=1;
			boardPieces[3].setRemovable(false); boardPieces[10].setRemovable(false); boardPieces[18].setRemovable(false);
		} 
		
		if((piece[6].getIcon()==bluecircle)&&(piece[11].getIcon()==bluecircle)&&(piece[15].getIcon()==bluecircle)&&!bmills[10]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[10]=true;
			toRemove=1;
			boardPieces[6].setRemovable(false); boardPieces[11].setRemovable(false); boardPieces[15].setRemovable(false);
		} 
		
		if((piece[1].getIcon()==bluecircle)&&(piece[4].getIcon()==bluecircle)&&(piece[7].getIcon()==bluecircle)&&!bmills[11]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[11]=true;
			toRemove=1;
			boardPieces[1].setRemovable(false); boardPieces[4].setRemovable(false); boardPieces[7].setRemovable(false);
		} 
		
		if((piece[16].getIcon()==bluecircle)&&(piece[19].getIcon()==bluecircle)&&(piece[22].getIcon()==bluecircle)&&!bmills[12]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[12]=true;
			toRemove=1;
			boardPieces[16].setRemovable(false); boardPieces[19].setRemovable(false); boardPieces[22].setRemovable(false);
		} 
		
		if((piece[8].getIcon()==bluecircle)&&(piece[12].getIcon()==bluecircle)&&(piece[17].getIcon()==bluecircle)&&!bmills[13]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[13]=true;
			toRemove=1;
			boardPieces[8].setRemovable(false); boardPieces[12].setRemovable(false); boardPieces[17].setRemovable(false);
		} 
		
		if((piece[5].getIcon()==bluecircle)&&(piece[13].getIcon()==bluecircle)&&(piece[20].getIcon()==bluecircle)&&!bmills[14]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[14]=true;
			toRemove=1;
			boardPieces[5].setRemovable(false); boardPieces[13].setRemovable(false); boardPieces[20].setRemovable(false);
		} 
		
		if((piece[2].getIcon()==bluecircle)&&(piece[14].getIcon()==bluecircle)&&(piece[23].getIcon()==bluecircle)&&!bmills[15]){
			JOptionPane.showMessageDialog(this, "Blue has a mill, pick a red piece to remove.");
			bmills[15]=true;
			toRemove=1;
			boardPieces[2].setRemovable(false); boardPieces[14].setRemovable(false); boardPieces[23].setRemovable(false);
		}
			
		if((piece[0].getIcon()==redcircle)&&(piece[1].getIcon()==redcircle)&&(piece[2].getIcon()==redcircle)&&!rmills[0]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[0]=true;
			toRemove=-1;
			boardPieces[0].setRemovable(false); boardPieces[1].setRemovable(false); boardPieces[2].setRemovable(false);
		} 
			
		if((piece[3].getIcon()==redcircle)&&(piece[4].getIcon()==redcircle)&&(piece[5].getIcon()==redcircle)&&!rmills[1]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[1]=true;
			toRemove=-1;
			boardPieces[3].setRemovable(false); boardPieces[4].setRemovable(false); boardPieces[5].setRemovable(false);
		}
		
		if((piece[6].getIcon()==redcircle)&&(piece[7].getIcon()==redcircle)&&(piece[8].getIcon()==redcircle)&&!rmills[2]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[2]=true;
			toRemove=-1;
			boardPieces[6].setRemovable(false); boardPieces[7].setRemovable(false); boardPieces[8].setRemovable(false);
		} 
			
		if((piece[9].getIcon()==redcircle)&&(piece[10].getIcon()==redcircle)&&(piece[11].getIcon()==redcircle)&&!rmills[3]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[3]=true;
			toRemove=-1;
			boardPieces[9].setRemovable(false); boardPieces[10].setRemovable(false); boardPieces[11].setRemovable(false);
		} 
			
		if((piece[12].getIcon()==redcircle)&&(piece[13].getIcon()==redcircle)&&(piece[14].getIcon()==redcircle)&&!rmills[4]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[4]=true;
			toRemove=-1;
			boardPieces[12].setRemovable(false); boardPieces[13].setRemovable(false); boardPieces[14].setRemovable(false);
		} 
			
		if((piece[15].getIcon()==redcircle)&&(piece[16].getIcon()==redcircle)&&(piece[17].getIcon()==redcircle)&&!rmills[5]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[5]=true;
			toRemove=-1;
			boardPieces[15].setRemovable(false); boardPieces[16].setRemovable(false); boardPieces[17].setRemovable(false);
		} 
		
		if((piece[18].getIcon()==redcircle)&&(piece[19].getIcon()==redcircle)&&(piece[20].getIcon()==redcircle)&&!rmills[6]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[6]=true;
			toRemove=-1;
			boardPieces[18].setRemovable(false); boardPieces[19].setRemovable(false); boardPieces[20].setRemovable(false);
		} 
			
		if((piece[21].getIcon()==redcircle)&&(piece[22].getIcon()==redcircle)&&(piece[23].getIcon()==redcircle)&&!rmills[7]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[7]=true;
			toRemove=-1;
			boardPieces[21].setRemovable(false); boardPieces[22].setRemovable(false); boardPieces[23].setRemovable(false);
		} 
			
		if((piece[0].getIcon()==redcircle)&&(piece[9].getIcon()==redcircle)&&(piece[21].getIcon()==redcircle)&&!rmills[8]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[8]=true;
			toRemove=-1;
			boardPieces[0].setRemovable(false); boardPieces[9].setRemovable(false); boardPieces[21].setRemovable(false);
		} 
			
		if((piece[3].getIcon()==redcircle)&&(piece[10].getIcon()==redcircle)&&(piece[18].getIcon()==redcircle)&&!rmills[9]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[9]=true;
			toRemove=-1;
			boardPieces[3].setRemovable(false); boardPieces[10].setRemovable(false); boardPieces[18].setRemovable(false);
		}
			
		if((piece[6].getIcon()==redcircle)&&(piece[11].getIcon()==redcircle)&&(piece[15].getIcon()==redcircle)&&!rmills[10]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[10]=true;
			toRemove=-1;
			boardPieces[6].setRemovable(false); boardPieces[11].setRemovable(false); boardPieces[15].setRemovable(false);
		} 
		
		if((piece[1].getIcon()==redcircle)&&(piece[4].getIcon()==redcircle)&&(piece[7].getIcon()==redcircle)&&!rmills[11]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[11]=true;
			toRemove=-1;
			boardPieces[1].setRemovable(false); boardPieces[4].setRemovable(false); boardPieces[7].setRemovable(false);
		} 
			
		if((piece[16].getIcon()==redcircle)&&(piece[19].getIcon()==redcircle)&&(piece[22].getIcon()==redcircle)&&!rmills[12]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[12]=true;
			toRemove=-1;
			boardPieces[16].setRemovable(false); boardPieces[19].setRemovable(false); boardPieces[22].setRemovable(false);
		} 
			
		if((piece[8].getIcon()==redcircle)&&(piece[12].getIcon()==redcircle)&&(piece[17].getIcon()==redcircle)&&!rmills[13]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[13]=true;
			toRemove=-1;
			boardPieces[8].setRemovable(false); boardPieces[12].setRemovable(false); boardPieces[17].setRemovable(false);
		} 
			
		if((piece[5].getIcon()==redcircle)&&(piece[13].getIcon()==redcircle)&&(piece[20].getIcon()==redcircle)&&!rmills[14]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[14]=true;
			toRemove=-1;
			boardPieces[5].setRemovable(false); boardPieces[13].setRemovable(false); boardPieces[20].setRemovable(false);
		} 
		
		if((piece[2].getIcon()==redcircle)&&(piece[14].getIcon()==redcircle)&&(piece[23].getIcon()==redcircle)&&!rmills[15]){
			JOptionPane.showMessageDialog(this, "Red has a mill, pick a blue piece to remove.");
			rmills[15]=true;
			toRemove=-1;
			boardPieces[2].setRemovable(false); boardPieces[14].setRemovable(false); boardPieces[23].setRemovable(false);
		} 
	}
	
	public void checkForNoMills(){
		
		if(!((piece[0].getIcon()==bluecircle)&&(piece[1].getIcon()==bluecircle)&&(piece[2].getIcon()==bluecircle))){
			bmills[0]=false;
		}
		
		if(!((piece[3].getIcon()==bluecircle)&&(piece[4].getIcon()==bluecircle)&&(piece[5].getIcon()==bluecircle))){
			bmills[1]=false;
		}
		
		if(!((piece[6].getIcon()==bluecircle)&&(piece[7].getIcon()==bluecircle)&&(piece[8].getIcon()==bluecircle))){
			bmills[2]=false;
		} 
		
		if(!((piece[9].getIcon()==bluecircle)&&(piece[10].getIcon()==bluecircle)&&(piece[11].getIcon()==bluecircle))){
			bmills[3]=false;
		} 
		
		if(!((piece[12].getIcon()==bluecircle)&&(piece[13].getIcon()==bluecircle)&&(piece[14].getIcon()==bluecircle))){
			bmills[4]=false;
		} 
		
		if(!((piece[15].getIcon()==bluecircle)&&(piece[16].getIcon()==bluecircle)&&(piece[17].getIcon()==bluecircle))){
			bmills[5]=false;
		} 
		
		if(!((piece[18].getIcon()==bluecircle)&&(piece[19].getIcon()==bluecircle)&&(piece[20].getIcon()==bluecircle))){
			bmills[6]=false;
		} 
		
		if(!((piece[21].getIcon()==bluecircle)&&(piece[22].getIcon()==bluecircle)&&(piece[23].getIcon()==bluecircle))){
			bmills[7]=false;
		} 
		
		if(!((piece[0].getIcon()==bluecircle)&&(piece[9].getIcon()==bluecircle)&&(piece[21].getIcon()==bluecircle))){
			bmills[8]=false;
		}
		
		if(!((piece[3].getIcon()==bluecircle)&&(piece[10].getIcon()==bluecircle)&&(piece[18].getIcon()==bluecircle))){
			bmills[9]=false;
		} 
		
		if(!((piece[6].getIcon()==bluecircle)&&(piece[11].getIcon()==bluecircle)&&(piece[15].getIcon()==bluecircle))){
			bmills[10]=false;
		} 
		
		if(!((piece[1].getIcon()==bluecircle)&&(piece[4].getIcon()==bluecircle)&&(piece[7].getIcon()==bluecircle))){
			bmills[11]=false;
		} 
		
		if(!((piece[16].getIcon()==bluecircle)&&(piece[19].getIcon()==bluecircle)&&(piece[22].getIcon()==bluecircle))){
			bmills[12]=false;
		} 
		
		if(!((piece[8].getIcon()==bluecircle)&&(piece[12].getIcon()==bluecircle)&&(piece[17].getIcon()==bluecircle))){
			bmills[13]=false;
		} 
		
		if(!((piece[5].getIcon()==bluecircle)&&(piece[13].getIcon()==bluecircle)&&(piece[20].getIcon()==bluecircle))){
			bmills[14]=false;
		} 
		
		if(!((piece[2].getIcon()==bluecircle)&&(piece[14].getIcon()==bluecircle)&&(piece[23].getIcon()==bluecircle))){
			bmills[15]=false;
		}
			
		if(!((piece[0].getIcon()==redcircle)&&(piece[1].getIcon()==redcircle)&&(piece[2].getIcon()==redcircle))){
			rmills[0]=false;
		} 
			
		if(!((piece[3].getIcon()==redcircle)&&(piece[4].getIcon()==redcircle)&&(piece[5].getIcon()==redcircle))){
			rmills[1]=false;
		}
		
		if(!((piece[6].getIcon()==redcircle)&&(piece[7].getIcon()==redcircle)&&(piece[8].getIcon()==redcircle))){
			rmills[2]=false;
		} 
			
		if(!((piece[9].getIcon()==redcircle)&&(piece[10].getIcon()==redcircle)&&(piece[11].getIcon()==redcircle))){;
			rmills[3]=false;
		} 
			
		if(!((piece[12].getIcon()==redcircle)&&(piece[13].getIcon()==redcircle)&&(piece[14].getIcon()==redcircle))){
			rmills[4]=false;
		} 
			
		if(!((piece[15].getIcon()==redcircle)&&(piece[16].getIcon()==redcircle)&&(piece[17].getIcon()==redcircle))){
			rmills[5]=false;
		} 
		
		if(!((piece[18].getIcon()==redcircle)&&(piece[19].getIcon()==redcircle)&&(piece[20].getIcon()==redcircle))){
			rmills[6]=false;
		} 
			
		if(!((piece[21].getIcon()==redcircle)&&(piece[22].getIcon()==redcircle)&&(piece[23].getIcon()==redcircle))){
			rmills[7]=false;
		} 
			
		if(!((piece[0].getIcon()==redcircle)&&(piece[9].getIcon()==redcircle)&&(piece[21].getIcon()==redcircle))){
			rmills[8]=false;
		} 
			
		if(!((piece[3].getIcon()==redcircle)&&(piece[10].getIcon()==redcircle)&&(piece[18].getIcon()==redcircle))){
			rmills[9]=false;
		}
			
		if(!((piece[6].getIcon()==redcircle)&&(piece[11].getIcon()==redcircle)&&(piece[15].getIcon()==redcircle))){
			rmills[10]=false;
		} 
		
		if(!((piece[1].getIcon()==redcircle)&&(piece[4].getIcon()==redcircle)&&(piece[7].getIcon()==redcircle))){
			rmills[11]=false;
		} 
			
		if(!((piece[16].getIcon()==redcircle)&&(piece[19].getIcon()==redcircle)&&(piece[22].getIcon()==redcircle))){
			rmills[12]=false;
		} 
			
		if(!((piece[8].getIcon()==redcircle)&&(piece[12].getIcon()==redcircle)&&(piece[17].getIcon()==redcircle))){
			rmills[13]=false;
		} 
			
		if(!((piece[5].getIcon()==redcircle)&&(piece[13].getIcon()==redcircle)&&(piece[20].getIcon()==redcircle))){
			rmills[14]=false;
		} 
		
		if(!((piece[2].getIcon()==redcircle)&&(piece[14].getIcon()==redcircle)&&(piece[23].getIcon()==redcircle))){;
			rmills[15]=false;
		}
		
		
	}
	
	public void setAbleToRemove(){
		
		if((!(bmills[0]) && !(bmills[8])) && (!(rmills[0]) && !(rmills[8]))){
			boardPieces[0].setRemovable(true);
		}
		
		if((!(bmills[0]) && !(bmills[11])) && (!(rmills[0]) && !(rmills[11]))){
			boardPieces[1].setRemovable(true);
		}
		
		if((!(bmills[0]) && !(bmills[15])) && (!(rmills[0]) && !(rmills[15]))){
			boardPieces[2].setRemovable(true);
		}
		
		if((!(bmills[1]) && !(bmills[9])) && (!(rmills[1]) && !(rmills[9]))){
			boardPieces[3].setRemovable(true);
		}
		
		if((!(bmills[1]) && !(bmills[11])) && (!(rmills[1]) && !(rmills[11]))){
			boardPieces[4].setRemovable(true);
		}
		
		if((!(bmills[1]) && !(bmills[14])) && (!(rmills[1]) && !(rmills[14]))){
			boardPieces[5].setRemovable(true);
		}
		
		if((!(bmills[2]) && !(bmills[10])) && (!(rmills[2]) && !(rmills[10]))){
			boardPieces[6].setRemovable(true);
		}
		
		if((!(bmills[2]) && !(bmills[11])) && (!(rmills[2]) && !(rmills[11]))){
			boardPieces[7].setRemovable(true);
		}

		if((!(bmills[2]) && !(bmills[13])) && (!(rmills[2]) && !(rmills[13]))){
			boardPieces[8].setRemovable(true);
		}
		
		if((!(bmills[3]) && !(bmills[8])) && (!(rmills[3]) && !(rmills[8]))){
			boardPieces[9].setRemovable(true);
		}
		
		if((!(bmills[3]) && !(bmills[9])) && (!(rmills[3]) && !(rmills[9]))){
			boardPieces[10].setRemovable(true);
		}
		
		if((!(bmills[3]) && !(bmills[10])) && (!(rmills[3]) && !(rmills[10]))){
			boardPieces[11].setRemovable(true);
		}
		
		if((!(bmills[4]) && !(bmills[13])) && (!(rmills[4]) && !(rmills[13]))){
			boardPieces[12].setRemovable(true);
		}
		
		if((!(bmills[4]) && !(bmills[14])) && (!(rmills[4]) && !(rmills[14]))){
			boardPieces[13].setRemovable(true);
		}
		
		if((!(bmills[4]) && !(bmills[15])) && (!(rmills[4]) && !(rmills[15]))){
			boardPieces[14].setRemovable(true);
		}
		
		if((!(bmills[5]) && !(bmills[10])) && (!(rmills[5]) && !(rmills[10]))){
			boardPieces[15].setRemovable(true);
		}
		
		if((!(bmills[5]) && !(bmills[12])) && (!(rmills[5]) && !(rmills[12]))){
			boardPieces[16].setRemovable(true);
		}
		
		if((!(bmills[5]) && !(bmills[13])) && (!(rmills[5]) && !(rmills[13]))){
			boardPieces[17].setRemovable(true);
		}
		
		if((!(bmills[6]) && !(bmills[9])) && (!(rmills[6]) && !(rmills[9]))){
			boardPieces[18].setRemovable(true);
		}
		
		if((!(bmills[6]) && !(bmills[12])) && (!(rmills[6]) && !(rmills[12]))){
			boardPieces[19].setRemovable(true);
		}
		
		if((!(bmills[6]) && !(bmills[14])) && (!(rmills[6]) && !(rmills[14]))){
			boardPieces[20].setRemovable(true);
		}
		
		if((!(bmills[7]) && !(bmills[8])) && (!(rmills[7]) && !(rmills[8]))){
			boardPieces[21].setRemovable(true);
		}
		
		if((!(bmills[7]) && !(bmills[12])) && (!(rmills[7]) && !(rmills[12]))){
			boardPieces[22].setRemovable(true);
		}
		
		if((!(bmills[7]) && !(bmills[15])) && (!(rmills[7]) && !(rmills[15]))){
			boardPieces[23].setRemovable(true);
		}
		
	}
	
	public void deadlocked(){
		
		if((boardPieces[0].getLabel().getIcon()==redcircle || boardPieces[0].getLabel().getIcon()==bluecircle)
				&& (boardPieces[1].getLabel().getIcon()==redcircle || boardPieces[1].getLabel().getIcon()==bluecircle)
				&& (boardPieces[9].getLabel().getIcon()==redcircle || boardPieces[9].getLabel().getIcon()==bluecircle)){
			boardPieces[0].setDeadlocked(true);
		} else {
			boardPieces[0].setDeadlocked(false);
		}
		
		if((boardPieces[1].getLabel().getIcon()==redcircle || boardPieces[1].getLabel().getIcon()==bluecircle)
				&& (boardPieces[0].getLabel().getIcon()==redcircle || boardPieces[0].getLabel().getIcon()==bluecircle)
				&& (boardPieces[2].getLabel().getIcon()==redcircle || boardPieces[2].getLabel().getIcon()==bluecircle)
				&& (boardPieces[4].getLabel().getIcon()==redcircle || boardPieces[4].getLabel().getIcon()==bluecircle)){
			boardPieces[1].setDeadlocked(true);
		} else {
			boardPieces[1].setDeadlocked(false);
		}
		
		if((boardPieces[2].getLabel().getIcon()==redcircle || boardPieces[2].getLabel().getIcon()==bluecircle)
				&& (boardPieces[1].getLabel().getIcon()==redcircle || boardPieces[1].getLabel().getIcon()==bluecircle)
				&& (boardPieces[14].getLabel().getIcon()==redcircle || boardPieces[14].getLabel().getIcon()==bluecircle)){
			boardPieces[2].setDeadlocked(true);
		} else {
			boardPieces[2].setDeadlocked(false);
		}
		
		if((boardPieces[3].getLabel().getIcon()==redcircle || boardPieces[3].getLabel().getIcon()==bluecircle)
				&& (boardPieces[4].getLabel().getIcon()==redcircle || boardPieces[4].getLabel().getIcon()==bluecircle)
				&& (boardPieces[10].getLabel().getIcon()==redcircle || boardPieces[10].getLabel().getIcon()==bluecircle)){
			boardPieces[3].setDeadlocked(true);
		} else {
			boardPieces[3].setDeadlocked(false);
		}
		
		if((boardPieces[4].getLabel().getIcon()==redcircle || boardPieces[4].getLabel().getIcon()==bluecircle)
				&& (boardPieces[1].getLabel().getIcon()==redcircle || boardPieces[1].getLabel().getIcon()==bluecircle)
				&& (boardPieces[3].getLabel().getIcon()==redcircle || boardPieces[3].getLabel().getIcon()==bluecircle)
				&& (boardPieces[5].getLabel().getIcon()==redcircle || boardPieces[5].getLabel().getIcon()==bluecircle)
				&& (boardPieces[7].getLabel().getIcon()==redcircle || boardPieces[7].getLabel().getIcon()==bluecircle)){
			boardPieces[4].setDeadlocked(true);
		} else {
			boardPieces[4].setDeadlocked(false);
		}
		
		if((boardPieces[5].getLabel().getIcon()==redcircle || boardPieces[5].getLabel().getIcon()==bluecircle)
				&& (boardPieces[4].getLabel().getIcon()==redcircle || boardPieces[4].getLabel().getIcon()==bluecircle)
				&& (boardPieces[13].getLabel().getIcon()==redcircle || boardPieces[13].getLabel().getIcon()==bluecircle)){
			boardPieces[5].setDeadlocked(true);
		} else {
			boardPieces[5].setDeadlocked(false);
		}
		
		if((boardPieces[6].getLabel().getIcon()==redcircle || boardPieces[6].getLabel().getIcon()==bluecircle)
				&& (boardPieces[7].getLabel().getIcon()==redcircle || boardPieces[7].getLabel().getIcon()==bluecircle)
				&& (boardPieces[11].getLabel().getIcon()==redcircle || boardPieces[11].getLabel().getIcon()==bluecircle)){
			boardPieces[6].setDeadlocked(true);
		} else {
			boardPieces[6].setDeadlocked(false);
		}
		
		if((boardPieces[7].getLabel().getIcon()==redcircle || boardPieces[7].getLabel().getIcon()==bluecircle)
				&& (boardPieces[4].getLabel().getIcon()==redcircle || boardPieces[4].getLabel().getIcon()==bluecircle)
				&& (boardPieces[6].getLabel().getIcon()==redcircle || boardPieces[6].getLabel().getIcon()==bluecircle)
				&& (boardPieces[8].getLabel().getIcon()==redcircle || boardPieces[8].getLabel().getIcon()==bluecircle)){
			boardPieces[7].setDeadlocked(true);
		} else {
			boardPieces[7].setDeadlocked(false);
		}
		
		if((boardPieces[8].getLabel().getIcon()==redcircle || boardPieces[8].getLabel().getIcon()==bluecircle)
				&& (boardPieces[7].getLabel().getIcon()==redcircle || boardPieces[7].getLabel().getIcon()==bluecircle)
				&& (boardPieces[12].getLabel().getIcon()==redcircle || boardPieces[12].getLabel().getIcon()==bluecircle)){
			boardPieces[8].setDeadlocked(true);
		} else {
			boardPieces[8].setDeadlocked(false);
		}
		
		if((boardPieces[9].getLabel().getIcon()==redcircle || boardPieces[9].getLabel().getIcon()==bluecircle)
				&& (boardPieces[0].getLabel().getIcon()==redcircle || boardPieces[0].getLabel().getIcon()==bluecircle)
				&& (boardPieces[10].getLabel().getIcon()==redcircle || boardPieces[10].getLabel().getIcon()==bluecircle)
				&& (boardPieces[21].getLabel().getIcon()==redcircle || boardPieces[21].getLabel().getIcon()==bluecircle)){
			boardPieces[9].setDeadlocked(true);
		} else {
			boardPieces[9].setDeadlocked(false);
		}
		
		if((boardPieces[10].getLabel().getIcon()==redcircle || boardPieces[10].getLabel().getIcon()==bluecircle)
				&& (boardPieces[3].getLabel().getIcon()==redcircle || boardPieces[3].getLabel().getIcon()==bluecircle)
				&& (boardPieces[9].getLabel().getIcon()==redcircle || boardPieces[9].getLabel().getIcon()==bluecircle)
				&& (boardPieces[11].getLabel().getIcon()==redcircle || boardPieces[11].getLabel().getIcon()==bluecircle)
				&& (boardPieces[18].getLabel().getIcon()==redcircle || boardPieces[18].getLabel().getIcon()==bluecircle)){
			boardPieces[10].setDeadlocked(true);
		} else {
			boardPieces[10].setDeadlocked(false);
		}
		
		if((boardPieces[11].getLabel().getIcon()==redcircle || boardPieces[11].getLabel().getIcon()==bluecircle)
				&& (boardPieces[6].getLabel().getIcon()==redcircle || boardPieces[6].getLabel().getIcon()==bluecircle)
				&& (boardPieces[10].getLabel().getIcon()==redcircle || boardPieces[10].getLabel().getIcon()==bluecircle)
				&& (boardPieces[15].getLabel().getIcon()==redcircle || boardPieces[15].getLabel().getIcon()==bluecircle)){
			boardPieces[11].setDeadlocked(true);
		} else {
			boardPieces[11].setDeadlocked(false);
		}
		
		if((boardPieces[12].getLabel().getIcon()==redcircle || boardPieces[12].getLabel().getIcon()==bluecircle)
				&& (boardPieces[8].getLabel().getIcon()==redcircle || boardPieces[8].getLabel().getIcon()==bluecircle)
				&& (boardPieces[13].getLabel().getIcon()==redcircle || boardPieces[13].getLabel().getIcon()==bluecircle)
				&& (boardPieces[17].getLabel().getIcon()==redcircle || boardPieces[17].getLabel().getIcon()==bluecircle)){
			boardPieces[12].setDeadlocked(true);
		} else {
			boardPieces[12].setDeadlocked(false);
		}
		 
		if((boardPieces[13].getLabel().getIcon()==redcircle || boardPieces[13].getLabel().getIcon()==bluecircle)
				&& (boardPieces[5].getLabel().getIcon()==redcircle || boardPieces[5].getLabel().getIcon()==bluecircle)
				&& (boardPieces[12].getLabel().getIcon()==redcircle || boardPieces[12].getLabel().getIcon()==bluecircle)
				&& (boardPieces[14].getLabel().getIcon()==redcircle || boardPieces[14].getLabel().getIcon()==bluecircle)
				&& (boardPieces[20].getLabel().getIcon()==redcircle || boardPieces[20].getLabel().getIcon()==bluecircle)){
			boardPieces[13].setDeadlocked(true);
		} else {
			boardPieces[13].setDeadlocked(false);
		}
		
		if((boardPieces[14].getLabel().getIcon()==redcircle || boardPieces[14].getLabel().getIcon()==bluecircle)
				&& (boardPieces[2].getLabel().getIcon()==redcircle || boardPieces[2].getLabel().getIcon()==bluecircle)
				&& (boardPieces[13].getLabel().getIcon()==redcircle || boardPieces[13].getLabel().getIcon()==bluecircle)
				&& (boardPieces[23].getLabel().getIcon()==redcircle || boardPieces[23].getLabel().getIcon()==bluecircle)){
			boardPieces[14].setDeadlocked(true);
		} else {
			boardPieces[14].setDeadlocked(false);
		}
		
		if((boardPieces[15].getLabel().getIcon()==redcircle || boardPieces[15].getLabel().getIcon()==bluecircle)
				&& (boardPieces[11].getLabel().getIcon()==redcircle || boardPieces[11].getLabel().getIcon()==bluecircle)
				&& (boardPieces[16].getLabel().getIcon()==redcircle || boardPieces[16].getLabel().getIcon()==bluecircle)){
			boardPieces[15].setDeadlocked(true);
		} else {
			boardPieces[15].setDeadlocked(false);
		}
		
		if((boardPieces[16].getLabel().getIcon()==redcircle || boardPieces[16].getLabel().getIcon()==bluecircle)
				&& (boardPieces[15].getLabel().getIcon()==redcircle || boardPieces[15].getLabel().getIcon()==bluecircle)
				&& (boardPieces[17].getLabel().getIcon()==redcircle || boardPieces[17].getLabel().getIcon()==bluecircle)
				&& (boardPieces[19].getLabel().getIcon()==redcircle || boardPieces[19].getLabel().getIcon()==bluecircle)){
			boardPieces[16].setDeadlocked(true);
		} else {
			boardPieces[16].setDeadlocked(false);
		}

		if((boardPieces[17].getLabel().getIcon()==redcircle || boardPieces[17].getLabel().getIcon()==bluecircle)
				&& (boardPieces[12].getLabel().getIcon()==redcircle || boardPieces[12].getLabel().getIcon()==bluecircle)
				&& (boardPieces[16].getLabel().getIcon()==redcircle || boardPieces[16].getLabel().getIcon()==bluecircle)){
			boardPieces[17].setDeadlocked(true);
		} else {
			boardPieces[17].setDeadlocked(false);
		}
		
		if((boardPieces[18].getLabel().getIcon()==redcircle || boardPieces[18].getLabel().getIcon()==bluecircle)
				&& (boardPieces[10].getLabel().getIcon()==redcircle || boardPieces[10].getLabel().getIcon()==bluecircle)
				&& (boardPieces[19].getLabel().getIcon()==redcircle || boardPieces[19].getLabel().getIcon()==bluecircle)){
			boardPieces[18].setDeadlocked(true);
		} else {
			boardPieces[18].setDeadlocked(false);
		}
		
		if((boardPieces[19].getLabel().getIcon()==redcircle || boardPieces[19].getLabel().getIcon()==bluecircle)
				&& (boardPieces[16].getLabel().getIcon()==redcircle || boardPieces[16].getLabel().getIcon()==bluecircle)
				&& (boardPieces[18].getLabel().getIcon()==redcircle || boardPieces[18].getLabel().getIcon()==bluecircle)
				&& (boardPieces[20].getLabel().getIcon()==redcircle || boardPieces[20].getLabel().getIcon()==bluecircle)
				&& (boardPieces[22].getLabel().getIcon()==redcircle || boardPieces[22].getLabel().getIcon()==bluecircle)){
			boardPieces[19].setDeadlocked(true);
		} else {
			boardPieces[19].setDeadlocked(false);
		}
		
		if((boardPieces[20].getLabel().getIcon()==redcircle || boardPieces[20].getLabel().getIcon()==bluecircle)
				&& (boardPieces[13].getLabel().getIcon()==redcircle || boardPieces[13].getLabel().getIcon()==bluecircle)
				&& (boardPieces[19].getLabel().getIcon()==redcircle || boardPieces[19].getLabel().getIcon()==bluecircle)){
			boardPieces[20].setDeadlocked(true);
		} else {
			boardPieces[20].setDeadlocked(false);
		}
		
		if((boardPieces[21].getLabel().getIcon()==redcircle || boardPieces[21].getLabel().getIcon()==bluecircle)
				&& (boardPieces[9].getLabel().getIcon()==redcircle || boardPieces[9].getLabel().getIcon()==bluecircle)
				&& (boardPieces[22].getLabel().getIcon()==redcircle || boardPieces[22].getLabel().getIcon()==bluecircle)){
			boardPieces[21].setDeadlocked(true);
		} else {
			boardPieces[21].setDeadlocked(false);
		}
		
		if((boardPieces[22].getLabel().getIcon()==redcircle || boardPieces[22].getLabel().getIcon()==bluecircle)
				&& (boardPieces[19].getLabel().getIcon()==redcircle || boardPieces[19].getLabel().getIcon()==bluecircle)
				&& (boardPieces[21].getLabel().getIcon()==redcircle || boardPieces[21].getLabel().getIcon()==bluecircle)
				&& (boardPieces[23].getLabel().getIcon()==redcircle || boardPieces[23].getLabel().getIcon()==bluecircle)){
			boardPieces[22].setDeadlocked(true);
		} else {
			boardPieces[22].setDeadlocked(false);
		}
		
		if((boardPieces[23].getLabel().getIcon()==redcircle || boardPieces[23].getLabel().getIcon()==bluecircle)
				&& (boardPieces[14].getLabel().getIcon()==redcircle || boardPieces[14].getLabel().getIcon()==bluecircle)
				&& (boardPieces[22].getLabel().getIcon()==redcircle || boardPieces[22].getLabel().getIcon()==bluecircle)){
			boardPieces[23].setDeadlocked(true);
		} else {
			boardPieces[23].setDeadlocked(false);
		}
		
		
	}
	
	public void removePiece(int toRemove){
		if(toRemove ==1){
			
		} else {
			
		}
	}

	
	
	/**
	 * This should check to make sure the pieces are not moving 
	 * should just cycle through and make sure that 
	 */
	
	 /**
     * This should check to make sure the pieces are not moving 
     * should just cycle through and make sure that 
     */
    
    public boolean checkMove(JLabel newLocation, JLabel oldLocation){
        if (!freeMoving)
            return true;
        else if( areAdjacent(newLocation, oldLocation) ){

            //System.out.println("THE ADJACENT THING WORKED");
            
            return true;
        }
     
        
        else{
            //System.out.println("DO NOT ALLOW MOVE!!!!!!");
            
            JOptionPane.showMessageDialog(this, "I cant let you do that Dave");
            //oldLocation.setVisible(true);
            return false;
            
    
        
        }
        
    }//end of the method
    
    
    /**
     * I needed a method to make sure that the points are adjacent and thus can be moved between. 
     * It takes in the two points and through a convuluted if else stuff finds out if they are adjacent.
     * this seemed like the most straight forward way to do it 
     */
    public boolean areAdjacent(JLabel oldLocation, JLabel newLocation){
        
    	//System.out.println("Locaition 1: "+oldLocation.getLocation());
    	//System.out.println("Loc   2: "+newLocation.getLocation());
    	
        //pt 0 and 1 are adjacent
        if( 
                ( oldLocation.getLocation().equals( piece[0].getLocation() )  &&
                  newLocation.getLocation().equals( piece[1].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[1]. getLocation())  &&
                  newLocation.getLocation().equals( piece[0].getLocation()   )
                  )
                
        
            )    return true;
        //if 1 and 2 are adjacent etc...
        else if( 
                ( oldLocation.getLocation().equals( piece[1].getLocation() )  &&
                  newLocation.getLocation().equals( piece[2].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[2]. getLocation())  &&
                  newLocation.getLocation().equals( piece[1].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[3].getLocation() )  &&
                  newLocation.getLocation().equals( piece[4].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[4]. getLocation())  &&
                  newLocation.getLocation().equals( piece[3].getLocation()  ) )
                
                )return true;        
        else if( 
                ( oldLocation.getLocation().equals( piece[4].getLocation() )  &&
                  newLocation.getLocation().equals( piece[5].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[5]. getLocation())  &&
                  newLocation.getLocation().equals( piece[4].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[6].getLocation() )  &&
                  newLocation.getLocation().equals( piece[7].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[7]. getLocation())  &&
                  newLocation.getLocation().equals( piece[6].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[7].getLocation() )  &&
                  newLocation.getLocation().equals( piece[8].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[8]. getLocation())  &&
                  newLocation.getLocation().equals( piece[7].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[9].getLocation() )  &&
                  newLocation.getLocation().equals( piece[10].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[10]. getLocation())  &&
                  newLocation.getLocation().equals( piece[9].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[11].getLocation() )  &&
                  newLocation.getLocation().equals( piece[10].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[10]. getLocation())  &&
                  newLocation.getLocation().equals( piece[11].getLocation()  ) )
                
                )return true;
        
        else if( 
                ( oldLocation.getLocation().equals( piece[12].getLocation() )  &&
                  newLocation.getLocation().equals( piece[13].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[13]. getLocation())  &&
                  newLocation.getLocation().equals( piece[12].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[13].getLocation() )  &&
                  newLocation.getLocation().equals( piece[14].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[14]. getLocation())  &&
                  newLocation.getLocation().equals( piece[13].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[15].getLocation() )  &&
                  newLocation.getLocation().equals( piece[16].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[16]. getLocation())  &&
                  newLocation.getLocation().equals( piece[15].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[16].getLocation() )  &&
                  newLocation.getLocation().equals( piece[17].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[17]. getLocation())  &&
                  newLocation.getLocation().equals( piece[16].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[18].getLocation() )  &&
                  newLocation.getLocation().equals( piece[19].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[19]. getLocation())  &&
                  newLocation.getLocation().equals( piece[18].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[19].getLocation() )  &&
                  newLocation.getLocation().equals( piece[20].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[20]. getLocation())  &&
                  newLocation.getLocation().equals( piece[19].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[21].getLocation() )  &&
                  newLocation.getLocation().equals( piece[22].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[22]. getLocation())  &&
                  newLocation.getLocation().equals( piece[21].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[22].getLocation() )  &&
                  newLocation.getLocation().equals( piece[23].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[23]. getLocation())  &&
                  newLocation.getLocation().equals( piece[22].getLocation()  ) )
                
                )return true;
        //*****
        //START OF VERTICLE LINES::!~~~!~!~!~!
        //****     ||        |       |         | 
        else if( 
                ( oldLocation.getLocation().equals( piece[0].getLocation() )  &&
                  newLocation.getLocation().equals( piece[9].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[9]. getLocation())  &&
                  newLocation.getLocation().equals( piece[0].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[9].getLocation() )  &&
                  newLocation.getLocation().equals( piece[21].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[21]. getLocation())  &&
                  newLocation.getLocation().equals( piece[9].getLocation()  ) )
                
                )return true;
        
        else if( 
                ( oldLocation.getLocation().equals( piece[3].getLocation() )  &&
                  newLocation.getLocation().equals( piece[10].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[10]. getLocation())  &&
                  newLocation.getLocation().equals( piece[3].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[10].getLocation() )  &&
                  newLocation.getLocation().equals( piece[18].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[18]. getLocation())  &&
                  newLocation.getLocation().equals( piece[10].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[6].getLocation() )  &&
                  newLocation.getLocation().equals( piece[11].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[11]. getLocation())  &&
                  newLocation.getLocation().equals( piece[6].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[11].getLocation() )  &&
                  newLocation.getLocation().equals( piece[15].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[15]. getLocation())  &&
                  newLocation.getLocation().equals( piece[11].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[1].getLocation() )  &&
                  newLocation.getLocation().equals( piece[4].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[4]. getLocation())  &&
                  newLocation.getLocation().equals( piece[1].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[4].getLocation() )  &&
                  newLocation.getLocation().equals( piece[7].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[7]. getLocation())  &&
                  newLocation.getLocation().equals( piece[4].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[16].getLocation() )  &&
                  newLocation.getLocation().equals( piece[19].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[19]. getLocation())  &&
                  newLocation.getLocation().equals( piece[16].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[19].getLocation() )  &&
                  newLocation.getLocation().equals( piece[22].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[22]. getLocation())  &&
                  newLocation.getLocation().equals( piece[19].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[8].getLocation() )  &&
                  newLocation.getLocation().equals( piece[12].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[12]. getLocation())  &&
                  newLocation.getLocation().equals( piece[8].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[12].getLocation() )  &&
                  newLocation.getLocation().equals( piece[17].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[17]. getLocation())  &&
                  newLocation.getLocation().equals( piece[12].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[5].getLocation() )  &&
                  newLocation.getLocation().equals( piece[13].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[13]. getLocation())  &&
                  newLocation.getLocation().equals( piece[5].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[13].getLocation() )  &&
                  newLocation.getLocation().equals( piece[20].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[20]. getLocation())  &&
                  newLocation.getLocation().equals( piece[13].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[14].getLocation() )  &&
                  newLocation.getLocation().equals( piece[2].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[2]. getLocation())  &&
                  newLocation.getLocation().equals( piece[14].getLocation()  ) )
                
                )return true;
        else if( 
                ( oldLocation.getLocation().equals( piece[14].getLocation() )  &&
                  newLocation.getLocation().equals( piece[23].getLocation() ) )
                ||
                ( oldLocation.getLocation().equals( piece[23]. getLocation())  &&
                  newLocation.getLocation().equals( piece[14].getLocation()  ) )
                
                )return true;
            
        else

            return false;
        
    }
	
	
	/**
	 * move a piece on the game board after all other chcks have been done
	 */
	public void movePiece(JLabel newLocation, JLabel oldLocation){

		oldLocation.setLocation(newLocation.getLocation());
		movingLabel.setIcon(null);
		blueTurn = !blueTurn;	
		placingPiece = !placingPiece;
		updateCounter();
	}
}